<template>
	<view class="custom-tabbar-wrap">
		<view class="blank-block"></view>
		<view class="custom-tabbar">
			<template v-for="(item, i) in tabbars">
				<view @click="changeTab(i)" class="item" :key="i">
					<u-image v-if="current===i" :src="item.selectedIconPath" width="48rpx" height="48rpx" :fade="false"></u-image>
					<u-image v-else :src="item.iconPath" width="48rpx" height="48rpx" :fade="false"></u-image>
					<view class="title">{{item.text}}</view>
				</view>
			</template>
		</view>
	</view>
	
</template>

<script>
	export default {
		props: ['current'],
		data() {
			return {
				cur: -1,
				routers: ['pages/index/index', 'pages/record/index', 'pages/center/index'],
				tabbars: [
					{
						iconPath: "/static/tabbar/icon-index.png",
						selectedIconPath: "/static/tabbar/icon-index-active.png",
						text: '首页',
						midButton: false,
						customIcon: true,
						url: '/pages/index/index'
					},
					{
						iconPath: "/static/tabbar/icon-record.png",
						selectedIconPath: "/static/tabbar/icon-record-active.png",
						text: '查询记录',
						midButton: false,
						customIcon: true,
						url: '/pages/record/index'
					},
					{
						iconPath: "/static/tabbar/icon-mine.png",
						selectedIconPath: "/static/tabbar/icon-mine-active.png",
						text: '我的',
						midButton: false,
						customIcon: true,
						url: '/pages/center/index'
					},
				]
			}
		},
		mounted() {
			this.cur = this.current
			
		},
		methods: {
			changeTab(index) {
				this.cur = index
				
				
				uni.switchTab({
					url: this.tabbars[index].url
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.custom-tabbar-wrap {
		.blank-block {
			height: 96rpx;
		}
		.custom-tabbar {
			width: 100%;
			position: fixed;
			bottom: 0;
			left: 0;
			z-index: 10000;
			
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			height: 96rpx;
			background: #FFFFFF;
			box-shadow: 0px -4px 12px 0px rgba(0, 0, 0, 0.06);
			
			.item {
				flex: 1;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				text-align: center;
				
				.title {
					font-size: 20rpx;
					font-family: SourceHanSansCN-Regular, SourceHanSansCN;
					font-weight: 400;
					color: #101010;
				}
			}
		}
	}
	
</style>
